import React from 'react'
import ReactDOM from 'react-dom'

class App extends React.Component {
  state = {
    count: 0,
  }
  render() {
    return (
      <>
        <h1>Hello world</h1>
        <h2>当前的数值：{this.state.count}</h2>
        <button onClick={this.handleClick}>点击+1</button>
      </>
    )
  }
  //   this.setState的作用
  // 1.修改state的数据
  // 2.重新调用render方法渲染界面
  handleClick = () => {
    console.log(this, this.state.count)
    this.setState({
      count: this.state.count + 1,
    })
  }
}

ReactDOM.render(<App />, document.getElementById('root'))
